<?php

// uncomment the following to define a path alias
// Yii::setPathOfAlias('local','path/to/local-folder');
Yii::setPathOfAlias('widgets', dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'widgets');

// This function is uses to quick call CVarDumper::dump
function debug($var, $exit = true, $level = 10, $format = true)
{
	CVarDumper::dump($var, $level, $format);
	if ($exit) exit;
}

// Management config by modules
$arrModules = require(dirname(__FILE__).DIRECTORY_SEPARATOR.'modules.php');
$modulesPath = dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR;
$mainConfig = array();
$importsConfig = array();
$componentsConfig = array();
$paramsConfig = require(dirname(__FILE__).DIRECTORY_SEPARATOR.'params.php');
foreach ($arrModules as $key => $module) {
	$moduleName = is_string($key) ? $key : $module;
	$configPath = $modulesPath . $moduleName . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR;
	if (file_exists($configPath.'main.php')) $mainConfig = CMap::mergeArray($mainConfig, require($configPath.'main.php'));
	if (file_exists($configPath.'imports.php')) $importsConfig = CMap::mergeArray($importsConfig, require($configPath.'imports.php'));
	if (file_exists($configPath.'components.php')) $componentsConfig = CMap::mergeArray($componentsConfig, require($configPath.'components.php'));
	if (file_exists($configPath.'params.php')) $paramsConfig = CMap::mergeArray($paramsConfig, require($configPath.'params.php'));
}

// This is the main Web application configuration. Any writable
// CWebApplication properties can be configured here.
return CMap::mergeArray(array(
	'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
	'name'=>'Demo Yii Framework',

	'preload'=>array(
		'log', // preloading 'log' component
		'bootstrap', // preload the bootstrap component
	),
	
	// Set default language
	'language'=>'en',
	
	// Set default theme
	'theme'=>'tb_bootstrap',

	// autoloading model and component classes
	'import'=>CMap::mergeArray(array(
		'application.models.*',
		'application.components.*',
		'ext.ciHelpers.*',
	),$importsConfig),

	'modules'=>CMap::mergeArray($arrModules, array(
		// uncomment the following to enable the Gii tool
		'gii'=>array(
			'class'=>'system.gii.GiiModule',
			'password'=>'123456',
			// If removed, Gii defaults to localhost only. Edit carefully to taste.
			'ipFilters'=>array('127.0.0.1','::1'),
			'generatorPaths'=>array(
				'bootstrap.gii', // since 0.9.1
			),
		),
	)),

	// application components
	'components'=>CMap::mergeArray(array(
		'user'=>array(
			// enable cookie-based authentication
			'allowAutoLogin'=>true,
		),
		// config asset manager
		'assetManager' => array(
			'class' => 'HAssetManager',
			//'baseUrl' => '/'
		),
		// uncomment the following to enable URLs in path-format
		'urlManager'=>array(
			'urlFormat'=>'path',
			'showScriptName'=>false,
			'rules'=>array(
				'<controller:\w+>/<id:\d+>'=>'<controller>/view',
				'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
				'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
			),
		),
		'bootstrap'=>array(
			'class'=>'ext.bootstrap.components.Bootstrap', // assuming you extracted bootstrap under extensions
			'responsiveCss'=>true, // Registers the Bootstrap responsive CSS.
		),
		/*'db'=>array(
			'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db',
		),*/
		// uncomment the following to use a MySQL database
		'db'=>array(
			'connectionString' => 'mysql:host=localhost;dbname=throwbook',
			'emulatePrepare' => true,
			'username' => 'root',
			'password' => '',
			'charset' => 'utf8',
			'tablePrefix' => 'tbl_',
		),
		'errorHandler'=>array(
			// use 'site/error' action to display errors
			'errorAction'=>'site/error',
		),
		'log'=>array(
			'class'=>'CLogRouter',
			'routes'=>array(
				array(
					'class'=>'CFileLogRoute',
					'levels'=>'error, warning',
				),
				// uncomment the following to show log messages on web pages
				/*
				array(
					'class'=>'CWebLogRoute',
				),
				*/
			),
		),
	),$componentsConfig),

	// application-level parameters that can be accessed
	// using Yii::app()->params['paramName']
	'params'=>$paramsConfig,
),$mainConfig);